package com.lwq.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import com.lwq.controller.ProjectController;
import com.lwq.model.SuperTableModel;

public class RightEditorView extends JPanel{
	private static RightEditorView instance = null;
	private SuperTableView mTableView = null;
	private JButton mUndateBtn = null;
	private JButton mAddMemBtn = null;
	public static RightEditorView getInstance() {
		if(instance == null){
			instance = new RightEditorView();
		}
		return instance;
	}
	
	public RightEditorView(){
		init();
		setEvent();
	}

	private void init(){
		setEnabled(true);
		setVisible(true);
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		mUndateBtn = new JButton("Update");
		mAddMemBtn = new JButton("AddMem");
		JPanel jp =  new JPanel();
		jp.add(mUndateBtn);
		jp.add(mAddMemBtn);
		add(jp);
		
		mTableView = new SuperTableView();
		mTableView.setEnabled(true);
		mTableView.setVisible(true);
		add(mTableView);
		setEditorBoard(null);
	}
	
	public void setEditorBoard(SuperTableModel model){
		if(model != null){
			mTableView.reLoadData(model);
		}
	}
	
	public SuperTableModel getEditorResult(){
		return mTableView.getResultData();
	}
	
	private void setEvent(){
		mUndateBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ProjectController.UpdateDataCommand();
			}
		});
		mAddMemBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ProjectController.addMemberCommand();
			}
		});
	}
	
}
